package io.wongxd.demo.page.kvHolder

import androidx.compose.foundation.layout.Column
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableLongStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.tooling.preview.Preview
import io.wongxd.demo.AppBtn
import io.wongxd.demo.V
import io.wongxd.solution.baseView.BaseComposeToolBarFgt
import io.wongxd.solution.util.tools.HHmm
import io.wongxd.solution.util.tools.yyyyMMddHHmmss

class FgtKvHolder : BaseComposeToolBarFgt() {
    override fun lazyInit() {

    }

    override val title: String
        get() = this.javaClass.simpleName

    @Composable
    override fun Render() {

        val timeMsState = remember { mutableLongStateOf(0L) }

        val byKeyStrState = remember { mutableStateOf("--") }

        Column {
            AppBtn(text = "存储当前时间戳") {
                PreferenceKV.timeMs = System.currentTimeMillis()
            }

            Text(text = "时间:${timeMsState.longValue}, format:${timeMsState.longValue.yyyyMMddHHmmss}")

            AppBtn(text = "读取存储中时间") {
                timeMsState.longValue = PreferenceKV.timeMs
            }

            V(number = 50)

            AppBtn(text = "通过key存储") {
                PreferenceKV.set("str", "key 存储 ${System.currentTimeMillis().HHmm}")
            }

            Text(text = "byKeyStr :${byKeyStrState.value}")

            AppBtn(text = "通过key读取") {
                byKeyStrState.value = PreferenceKV.get("str", "--")
            }
        }

    }

    @Preview(showBackground = true, backgroundColor = 0xffffffff)
    @Composable
    fun RenderPreView() {

    }
}